<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
</head>

<body>
    <script>
        /*    
        let p1 = new Promise((resolve, reject) => {
               $.ajax({
                   url: './data/1.json',
                   success([res]) {
                       resolve(res)
                   },
                   fail([err]) {
                       reject(err)
                   }
               })
           })
   
           p1.then((res) => {
               console.log(res);
               if (res.count >= 0) {
                   return new Promise((resolve, reject) => {
                       $.ajax({
                           url: './data/2.json',
                           success([res]) {
                               resolve(res)
                           }
                       })
                   })
               }
           }, (err) => {
               console.log(err)
           })
               .then((res) => {
                   console.log(res)
   
                   return new Promise((resolve, reject) => {
                       $.ajax({
                           url: './data/3.json',
                           success([res]) {
                               resolve(res)
                           }
                       })
                   })
               })
               .then((res) => {
                   console.log(res)
               }) */


        //封装

        function myPromise(URL) {
            return new Promise((resolve, reject) => {
                $.ajax({
                    url: URL,
                    success([res]) {
                        resolve(res);
                    }
                })
            })
        }

        myPromise('./data/1.json')
            .then(res => {
                console.log(res)
                if (res.count >= 0) {
                    return myPromise('./data/2.json')
                }
            })
            .then(res => {
                console.log(res);
                if (res.count >= 1) {
                    return myPromise('./data/3.json')
                }
            })
            .then(res => {
                console.log(res)
            })
    </script>
</body>

</html>